package invertTree

type TreeNode struct {
	Val   int
	Left  *TreeNode
	Right *TreeNode
}

/**
交换左右子树的位置
*/
func invertTree(root *TreeNode) *TreeNode {
	if root == nil {
		return root
	}
	var invert func(node *TreeNode)

	invert = func(node *TreeNode) {
		if node == nil {
			return
		}
		node.Left, node.Right = node.Right, node.Left
		invert(node.Left)
		invert(node.Right)
	}
	invert(root)
	return root
}
